//
//  Loan_repaymentView.m
//  JinFuThree
//
//  Created by 爱尚 on 2018/9/12.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "Loan_repaymentView.h"
#import "Loan_repaymentTableViewCell.h"


@interface Loan_repaymentView()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *repaymentTableView;
@property(nonatomic,strong)NSMutableArray *dataArr;

@property(nonatomic,strong)UIButton *cancelBtn;
@property(nonatomic,strong)UIButton *sureBtn;
@property(nonatomic,strong)UIView *grayView;
@property(nonatomic,strong)UIView *whiteView;
@end

@implementation Loan_repaymentView

-(instancetype)init{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.frame = CGRectMake(0, 0, ScreenWidthMao, ScreenHeight);
        [self initialize];
        
    }
    return self;
}

-(void)cancelBtnAction{
    
    for (UIView *tempView in [UIApplication sharedApplication].keyWindow.rootViewController.view.subviews) {
        if ([tempView isMemberOfClass: [Loan_repaymentView class]]) {
            [tempView removeFromSuperview];
        }
    }
}

-(void)sureBtnAction:(UIButton *)sender{
    
    
        [self cancelBtnAction];
    
}
-(void)initialize{
    self.backgroundColor = [UIColor clearColor];
    _grayView = [[UIView alloc]init];
    _grayView.backgroundColor = [UIColor blackColor];
    _grayView.alpha = 0.3;
    [self addSubview:_grayView];
    [_grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(self);
    }];
    
    _whiteView = [[UIView alloc]init];
    _whiteView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_whiteView];
    [_whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(self);
        make.height.mas_offset(@370);
        
    }];
    
    _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [_cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _cancelBtn.titleLabel.font = UIFontMaoNormal;
    [_cancelBtn addTarget:self action:@selector(cancelBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.whiteView addSubview:_cancelBtn];
    [_cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.whiteView.mas_left).offset(20);
        make.top.mas_equalTo(self.whiteView.mas_top).offset(20);
        make.height.mas_offset(@16);
    }];
    
    _sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_sureBtn setTitle:@"确定" forState:UIControlStateNormal];
    [_sureBtn setTitleColor:ThemeMaoColor forState:UIControlStateNormal];
    _sureBtn.titleLabel.font = UIFontMaoNormal;
    [_sureBtn addTarget:self action:@selector(sureBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.whiteView addSubview:_sureBtn];
    [_sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.whiteView.mas_right).offset(-20);
        make.centerY.height.mas_equalTo(self.cancelBtn);
    }];
    UIView *line1 = [[UIView alloc]init];
    line1.backgroundColor = ThemeMaoLineColor;
    [self.whiteView addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.whiteView);
        make.height.mas_offset(@0.5);
        make.top.mas_equalTo(self.cancelBtn.mas_bottom).offset(20);
    }];
    
    _repaymentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    _repaymentTableView.delegate = self;
    _repaymentTableView.dataSource = self;
    [_repaymentTableView registerClass:[Loan_repaymentTableViewCell class] forCellReuseIdentifier:@"Loan_repaymentTableViewCell"];
    
    _repaymentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_whiteView addSubview:_repaymentTableView];
    [self.repaymentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(line1.mas_bottom);
        make.left.right.mas_equalTo(self.whiteView);
        make.bottom.mas_equalTo(self.whiteView.mas_bottom).offset(-10);
    }];
    
    
    
    
    
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count+1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    Loan_repaymentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Loan_repaymentTableViewCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row == 0) {
        [cell.circleView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(cell.periodsLabel.mas_right).offset(17);
            make.top.mas_equalTo(cell.periodsLabel.mas_top).offset(0);
            make.width.height.mas_offset(@9);
        }];
        
        cell.topline.hidden  = YES;
    }
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 75;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}

-(void)show:(NSArray *)selectBankcardArr{
    self.dataArr = [[NSMutableArray alloc]initWithArray:selectBankcardArr];
    [self.repaymentTableView reloadData];
    [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:self];
}



-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [[NSMutableArray alloc]init];
    }
    return _dataArr;
}



@end
